package com.nuanshui.heatedloan.credit.service.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.credit.facade.AllinPayTransService;
import com.nuanshui.heatedloan.task.annotation.Task;
import com.nuanshui.heatedloan.task.facade.QuartzTaskManager;
import com.nuanshui.heatedloan.task.facade.bean.JobParams;
import com.nuanshui.heatedloan.task.facade.bean.JobProvider;
import com.nuanshui.heatedloan.task.facade.constant.TaskEnum;
import com.nuanshui.heatedloan.task.failover.TaskfailoverStrategyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * @author zss
 * @date 2017/7/28 16:18
 * @description  通联交易中间状态轮询处理
 * @Since
 */
@Component
public class TradeDetailJob {

    private Logger logger = LoggerFactory.getLogger(TradeDetailJob.class);

    @Reference(url= GlobalParam.TASK_DUBBO_SERVER,timeout= GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.TASK_DUBBO_SERVER_VERSION)
    private QuartzTaskManager quartzTaskManager;

    @Autowired
    private AllinPayTransService allinPayTransService;

    @Task(name = "TRADE_DETAIL_JOB", group = "TRADE_DETAIL", failover= TaskfailoverStrategyType.RETRY,retries=1)
    public void dealTradeDetailJob(JobParams jobParams){
//        LogUtil.info(logger, "---------------开始发送执行交易明细查询任务------------------");
//        String reqSn = jobParams.getBizKey();
//        LogUtil.info(logger, "--交易明细查询，交易流水号："+reqSn);
//        String retCode  = allinPayTransService.queryTrade("reqSn");
//        JobProvider jobProvider = new JobProvider(TaskEnum.TRADE_DETAIL_JOB.getName(),TaskEnum.TRADE_DETAIL_JOB.getGroup());
//        if("0000".equals(retCode)){
//            quartzTaskManager.stopJob(jobProvider);
//        }else if("2000".equals(retCode) || "2001".equals(retCode)||
//                "2003".equals(retCode)|| "2005".equals(retCode)||
//                "2007".equals(retCode)|| "2008".equals(retCode)){//依然处理交易处理状态
//            Calendar can = Calendar.getInstance();
//            jobProvider.getParams().setBizKey(retCode);
//            can.add(Calendar.MINUTE, 1);//1分钟执行
//            quartzTaskManager.addJob(jobProvider, can.getTime());
//        }else{
//            quartzTaskManager.stopJob(jobProvider);
//            LogUtil.info(logger, "---------------交易流水号为reqSn[ "+reqSn+" ]交易失败，请查询错误信息");
//        }
//        LogUtil.info(logger, "----------------完成发送执行交易明细查询任务------------------");
    }
}
